package com.car.config;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.util.Properties;

/**
 * 数据库连接池配置类
 */
public class DataSourceConfig {
    /**
     * 获取数据库连池接对象
     *
     * @return 数据库连接池对象
     */
    public static DataSource getDataSource() throws Exception {
        Properties properties = new Properties();
        properties.load(new FileInputStream("druid.properties"));
        return DruidDataSourceFactory.createDataSource(properties);
    }

    /**
     * 获取数据库连接对象
     *
     * @return 数据库连接对象
     * @throws Exception 异常
     */
    public static Connection getConnection() throws Exception {
        return getDataSource().getConnection();
    }
}
